home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / TELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  761 b   |  29 lines

  1. /* tell.c --- p 506 */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. main()
  6. {
  7.     int fhandle, count;
  8.     long curpos;
  9.     unsigned char buffer[80];
  10.                     /* Open the file "autoexec.bat." */
  11.     if ( (fhandle= open("c:\\autoexec.bat", O_RDONLY)) == -1)
  12.     {
  13.         printf("open failed");
  14.         exit(1);
  15.     }
  16.                 /* Display current position using "tell" */
  17.     curpos = tell(fhandle);
  18.     printf("Currently at position %ld in 'autoexec.bat'\n", curpos);
  19.             /* Now read 80 bytes and check position again */
  20.     if ((count = read(fhandle, buffer, 80)) == -1)
  21.     {
  22.         perror("read error");
  23.         exit(1);
  24.     }
  25.     printf("Read following 80 characters:\n");
  26.     write(1, buffer, count);
  27.     curpos = tell(fhandle);
  28.     printf("\nNow at position: %ld bytes from beginning\n", curpos);
  29. }